package com.xucy.springboot.code;

import java.util.Arrays;

/**
 * @Author xucy
 * @Date 2019-11-08 18:27
 * @Description
 **/

public class TestSort {

//    private static final int[] NUMBERS =
//            {49, 38, 65, 97, 76, 13, 27, 78, 34, 12, 64, 5, 4,
//                    62, 99, 98, 54, 56, 17, 18, 23, 34, 15, 35, 25, 53, 51};
//
     private static final int[] NUMBERS =
            {7, 6, 5, 8, 10, 13};

    public static void main(String[] args) {
        insertSort(NUMBERS);

    }

    //插入排序
    public static void insertSort(int[] array) {
         System.out.println(Arrays.toString(array) + " start");
         for (int i = 1; i < array.length; i++) {
             int temp = array[i];
             int j = i - 1;
             for (; j >= 0 && array[j] > temp; j--) {
              //将大于temp的值整体后移一个单位
                array[j + 1] = array[j];
             }
             array[j + 1] = temp;
             }
         System.out.println(Arrays.toString(array) + " end");
    }
}
